package com.hezuti.common.structure.list;

public class DllNode<T> {
	T value;
	DllNode<T> prev;
	DllNode<T> next;
	DoubleLinkedList<T> list;
	
	public DllNode() { // for header  
		this.value = null;  
		this.prev = this; // left  
		this.next = this; // right  
	}
	
	public DllNode(T value) {
		this.value = value;  
		this.prev = this;
		this.next = this;
	}
	
	public T getValue() {
		return value;
	}
	
	public DoubleLinkedList<T> getList() {
		return list;
	}
	
	public void add(DllNode<T> curr, DoubleLinkedList<T> list) {
		if(this.next == this) {
			this.list = list;
			this.prev = curr.prev;
			this.next = curr;
			curr.prev.next = this;  
			curr.prev = this;
			this.list.setSize(this.list.size()+1);
		}
	}
	
	public void remove() {
		if(this.next != this) {
			this.prev.next = this.next;
			this.next.prev = this.prev;
			this.list.setSize(this.list.size()-1);
			//reset
			this.prev = this.next = this;
		}
	}
}
